function hideDiv(div_id) {
	$("#" + div_id).animate({
		opacity : "hide"
	}, 300);
	location.reload("/GetResumeServlet");
}
function popupDiv(div_id) {
	var div_obj = $("#" + div_id);
	// 窗口宽度,高度
	var winWidth = $(window).width();
	var winHeight = $(window).height();
	// 弹出的div的宽度,高度
	var popHeight = div_obj.height();
	var popWidth = div_obj.width();
	div_obj.animate({
		opacity : "show",
		left : (winWidth - popWidth) / 2,
		top : (winHeight - popHeight) / 4,
		width : popWidth,
		height : popHeight
	}, 300);
}
$(function() {
	$(".pop_box").easydrag();
	$(".pop_box").setHandler(".pop_box .p_head");
});

function clickEditResume(count, id, div_id) {
	
	if(!RolePowerManager())
		{return;}
	
	$("#empid_edit").val($(counts[1]).text());
	$("#deptname_edit").val('0');
	$("#deptname_edit").text($(counts[2]).text());
	$("#deptname_edit").val('0');
	$("#dutyname_edit").text($(counts[3]).text());
	$("#deptname_edit").val('0');
	$("#eduname_edit").text($(counts[4]).text());
	$("#workcon_edit").val($(counts[5]).text());
	$("#score_edit").val($(counts[6]).text());
	$("#st_edit").val($(counts[7]).text());
	$("#et_edit").val($(counts[8]).text());
	$("#resumeid").val(id);
	datafill('edit',count);
	popupDiv(div_id);
}

function clickAddResume(div_id) {
	
	if(!RolePowerManager())
		{return;}
	
	datafill('add');
	popupDiv(div_id);
}

function addResume() {
	var empid = $("#empid_add").val();
	var deptname = $("#deptname_add").val();
	var dutyname = $("#dutyname_add").val();
	var eduname = $("#eduname_add").val();
	var workcon = $("#workcon_add").val();
	var score = $("#score_add").val();
	var st = $("#st_add").val();
	var et = $("#et_add").val();

	if (empid && deptname && dutyname && eduname && workcon && score && st
			&& et) {
		ResumeManagerService.addResume(empid, deptname, dutyname, eduname,
				workcon, score, st, et, function(data) {
					if (data) {
						alert("增加成功");
						location.reload("/GetResumeServlet");
					} else {
						alert("增加失败");
					}
				});
	} else {
		alert("有必填项未填！");
	}
}

function updateResume() {
	var empid = $("#empid_edit").val();
	var deptname = $("#deptname_edit").find("option:selected").text();
	var dutyname = $("#dutyname_edit").find("option:selected").text();
	var eduname = $("#eduname_edit").find("option:selected").text();
	var workcon = $("#workcon_edit").val();
	var score = $("#score_edit").val();
	var st = $("#st_edit").val();
	var et = $("#et_edit").val();
	var id = $("#resumeid").val();

	if (empid && deptname && dutyname && eduname && workcon && score && st
			&& et) {
		ResumeManagerService.updateResume(id, empid, deptname, dutyname,
				eduname, workcon, score, st, et, function(data) {
					if (data) {
						alert("修改成功");
						location.reload("/GetResumeServlet");
					} else {
						alert("修改失败");
					}
				});
	} else {
		alert("有必填项未填！");
	}
}

function deleteResume(id) {
	
	if(!RolePowerManager())
		{return;}
	
	ResumeManagerService.deleteById(id, function(data) {
		if (data) {
			alert("删除成功");
			location.reload("/GetResumeServlet");
		} else {
			alert("删除失败");
		}
	});
}

function changePageSize() {
	var ps = $("#pageSize").val();
	location.href = "GetResumeServlet?pageSize=" + ps;
}

function search() {
	if ($("#searchtype").val() == "empid") {
		if (isNaN($("#keycode").val())) {
			alert("请输入数字");
			return;
		}
	}
	$("#searchform").submit();
}

function datafill(o,count) {
	var eduname="#eduname_"+o;
	var deptname="#deptname_"+o;
	var dutyname="#dutyname_"+o;
	
	var td_edn = '#' + count + 4;
	var td_den = '#' + count + 2;
	var td_dun = '#' + count + 3;
	
	EducationManager.getAll(function(data) {

		for ( var i = 0; i < data.length; i++) {
			
			$(eduname).append(
					"<option value='" + data[i].id + "'>" + data[i].name
							+ "</option>");

			if($(td_edn).text()==data[i].name){
				$(eduname).val(data[i].id);
			}
		}
	});
	DeptManager.getALLDept(function(data) {

		for ( var i = 0; i < data.length; i++) {
			$(deptname).append(
					"<option value='" + data[i].id + "'>"
							+ data[i].name + "</option>");

			if($(td_den).text()==data[i].name){
				$(deptname).val(data[i].id);
			}
		}
	});
	DutyManager.getAllDuty(function(data) {

		for ( var i = 0; i < data.length; i++) {
			
			$(dutyname).append(
					"<option value='" + data[i].id + "'>" + data[i].name
							+ "</option>");

			if($(td_dun).text()==data[i].name){
				$(dutyname).val(data[i].id);
			}
		}
	});
}